home *** CD-ROM | disk | FTP | other *** search
/ Amiga News 95 / Amiga News 95.iso / dpat / dpat48 / dearch / sources / archiwindow2.c next >
C/C++ Source or Header  |  1993-11-14  |  11KB  |  363 lines

  1. /*
  2.  *  ArchiWindow2.c
  3.  *  
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <exec/lists.h>
  8. #include <exec/memory.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <libraries/amigaguide.h>
  16. #include <graphics/displayinfo.h>
  17. #include <graphics/gfxbase.h>
  18.  
  19. #include <clib/exec_protos.h>
  20. #include <clib/intuition_protos.h>
  21. #include <clib/gadtools_protos.h>
  22. #include <clib/graphics_protos.h>
  23. #include <clib/utility_protos.h>
  24.  
  25. #ifdef __SASC
  26. #include <pragmas/exec_pragmas.h>
  27. #include <pragmas/intuition_pragmas.h>
  28. #include <pragmas/gadtools_pragmas.h>
  29. #include <pragmas/graphics_pragmas.h>
  30. #include <pragmas/utility_pragmas.h>
  31. #endif
  32.  
  33. #include <string.h>
  34.  
  35. #define CATCOMP_NUMBERS
  36.  
  37. #include "ArchiWindow2.h"
  38. #include "PrefsWindow.h"
  39. #include "CrunchPrefs.h"
  40. #include "local_dearch.h"
  41. #include "dearchguide.h"
  42.  
  43. #include "dearch_strings.h"
  44.  
  45. BOOL ArchiGadget00Clicked( void );
  46. BOOL ArchiGadget10Clicked( void );
  47. BOOL ArchiGadget20Clicked( void );
  48. BOOL ArchiGadget30Clicked( void );
  49. BOOL ArchiGadget40Clicked( void );
  50. BOOL ArchiGadget50Clicked( void );
  51. BOOL ArchiGadget60Clicked( void );
  52. BOOL ArchiGadget70Clicked( void );
  53. void HandleArchiIDCMP( void );
  54. BOOL OpenArchiWindow( void );
  55. BOOL CloseArchiWindow( void );
  56.  
  57. extern BOOL OpenPrefsWindow(void);
  58.  
  59. struct Window                *ArchiWnd = NULL;
  60. static struct Gadget         *ArchiGList = NULL;
  61. static struct IntuiMessage    ArchiMsg;
  62. struct Gadget                *ArchiGadgets[8];
  63. static UWORD                  ArchiLeft = 82;
  64. static UWORD                  ArchiTop = 38;
  65. static UWORD                  ArchiWidth = 423;
  66. static UWORD                  ArchiHeight = 178;
  67. BOOL                          addflag;
  68. struct crunch                *nodecmd;
  69. char                         *oldoption, *oldext;
  70. BOOL                          oldrep;
  71.  
  72. static UWORD ArchiGTypes[] = {
  73.      STRING_KIND,
  74.      LISTVIEW_KIND,
  75.      BUTTON_KIND,
  76.      BUTTON_KIND,
  77.      BUTTON_KIND,
  78.      BUTTON_KIND,
  79.      BUTTON_KIND,
  80.      BUTTON_KIND
  81. };
  82.  
  83. static struct NewGadget ArchiNGad[] = {
  84.     68, 100, 258, 16, NULL, NULL, GD_ArchiGadget00, 0, NULL, (APTR)ArchiGadget00Clicked,
  85.     68, 22, 258, 74, NULL, NULL, GD_ArchiGadget10, PLACETEXT_ABOVE|NG_HIGHLABEL, NULL, (APTR)ArchiGadget10Clicked,
  86.     296, 153, 92, 19, NULL, NULL, GD_ArchiGadget20, PLACETEXT_IN, NULL, (APTR)ArchiGadget20Clicked,
  87.     296, 127, 92, 19, NULL, NULL, GD_ArchiGadget30, PLACETEXT_IN, NULL, (APTR)ArchiGadget30Clicked,
  88.     164, 152, 92, 19, NULL, NULL, GD_ArchiGadget40, PLACETEXT_IN, NULL, (APTR)ArchiGadget40Clicked,
  89.     22, 126, 92, 19, NULL, NULL, GD_ArchiGadget50, PLACETEXT_IN, NULL, (APTR)ArchiGadget50Clicked,
  90.     22, 152, 92, 19, NULL, NULL, GD_ArchiGadget60, PLACETEXT_IN, NULL, (APTR)ArchiGadget60Clicked,
  91.     164, 127, 92, 19, NULL, NULL, GD_ArchiGadget70, PLACETEXT_IN, NULL, (APTR)ArchiGadget70Clicked
  92. };
  93.  
  94. static ULONG ArchiGTags[] = {
  95.     (GTST_MaxChars), 256, (STRINGA_Justification), (GACT_STRINGCENTER), (TAG_DONE),
  96.         (GTLV_Labels), NULL, GTLV_Top, 8, (GTLV_ShowSelected), NULL, (GTLV_Selected), 0, (TAG_DONE),
  97.     (GT_Underscore), '_', (TAG_DONE),
  98.     (GT_Underscore), '_', (TAG_DONE),
  99.     (GT_Underscore), '_', (TAG_DONE),
  100.     (GT_Underscore), '_', (TAG_DONE),
  101.     (GT_Underscore), '_',(TAG_DONE),
  102.     (GT_Underscore), '_', (TAG_DONE)
  103. };
  104.  
  105. extern struct Library *GadToolsBase, *UtilityBase, *IntuitionBase;
  106. extern struct Window *PrefsWnd;
  107. extern struct List   myList;
  108. extern struct Gadget *PrefsGadgets[5];
  109. extern struct Screen *Scr;
  110. extern APTR VisualInfo;
  111. extern struct TextAttr topaz8;
  112.  
  113.  
  114. void HandleArchiIDCMP( void )
  115. {
  116.     struct IntuiMessage    *m;
  117.     BOOL            (*func)();
  118.         BOOL                    running = TRUE;
  119.         
  120.     while( (running) && (m = GT_GetIMsg( ArchiWnd->UserPort)) ) 
  121.         {
  122.         CopyMem(( char * )m, ( char * )&ArchiMsg, (long)sizeof( struct IntuiMessage ));
  123.  
  124.         GT_ReplyIMsg( m );
  125.  
  126.         switch ( ArchiMsg.Class ) 
  127.                 {
  128.             case    IDCMP_REFRESHWINDOW:
  129.                 GT_BeginRefresh( ArchiWnd );
  130.                 GT_EndRefresh( ArchiWnd, TRUE );
  131.                 break;
  132.  
  133.             case    IDCMP_CLOSEWINDOW:
  134.                 running = CloseArchiWindow();
  135.                 break;
  136.  
  137.             case    IDCMP_GADGETUP:
  138.                 func = ( void * )(( struct Gadget * )ArchiMsg.IAddress )->UserData;
  139.                 running = func();
  140.                 break;
  141.                                 
  142.                         case IDCMP_VANILLAKEY:
  143.                                 switch (ArchiMsg.Code) 
  144.                                 {                                                                         
  145.                                      case 'a':
  146.                                      case 'A':
  147.                                         running = ArchiGadget50Clicked();
  148.                                         break;
  149.                                         
  150.                                      case 'e':
  151.                                      case 'E':
  152.                                         running = ArchiGadget70Clicked();
  153.                                         break; 
  154.                                      
  155.                                      case 'o':
  156.                                      case 'O':
  157.                                         running = CloseArchiWindow();
  158.                                         break;                                       
  159.                                                  
  160.                                      case 's':
  161.                                      case 'S':
  162.                                         running = ArchiGadget30Clicked();
  163.                                         break;  
  164.                                         
  165.                                      case 'u':
  166.                                      case 'U':
  167.                                         running = ArchiGadget40Clicked();
  168.                                         break;  
  169.                                         
  170.                                      case 'v':
  171.                                      case 'V':
  172.                                         running = ArchiGadget60Clicked();
  173.                                         break;                                         
  174.                                 } 
  175.                                 
  176.                         case IDCMP_RAWKEY:
  177.                                 if (ArchiMsg.Code == 95)
  178.                                         running = HandleGadgetHelp(&ArchiMsg);      
  179.                                 break;                            
  180.                 }
  181.         }
  182. }
  183.  
  184. BOOL OpenArchiWindow( void )
  185. {
  186.     struct NewGadget    ng;
  187.     struct Gadget    *g;
  188.     struct TagItem    *tmp; 
  189.     UWORD        lc, tc;
  190.     UWORD        offx = Scr->WBorLeft, offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  191.  
  192.         LocaliseGadgets(ArchiNGad, Archi_CNT, MSG_ARCHIGAD00);
  193.         
  194.     if ( ! ( g = CreateContext( &ArchiGList )))
  195.         return( FALSE );
  196.  
  197.     for( lc = 0, tc = 0; lc < Archi_CNT; lc++ ) {
  198.  
  199.         CopyMem((char * )&ArchiNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  200.  
  201.         ng.ng_VisualInfo = VisualInfo;
  202.         ng.ng_TextAttr   = &topaz8;
  203.         ng.ng_LeftEdge  += offx;
  204.         ng.ng_TopEdge   += offy;
  205.                 
  206.                 
  207.         if ( ArchiGTypes[ lc ] == LISTVIEW_KIND ) 
  208.                 {
  209.           if ( tmp = FindTagItem( GTLV_ShowSelected, ( struct TagItem * )&ArchiGTags[ tc])) 
  210.                 tmp->ti_Data = (ULONG)ArchiGadgets[GD_ArchiGadget00 - 9];
  211.         }
  212.                 
  213.                 
  214.         ArchiGadgets[ lc ] = g = CreateGadgetA((ULONG)ArchiGTypes[ lc ], g, &ng, ( struct TagItem * )&ArchiGTags[ tc ] );
  215.  
  216.         while( ArchiGTags[ tc ] ) tc += 2;
  217.         tc++;
  218.  
  219.         if ( ! g )
  220.             return( FALSE );
  221.     }
  222.         
  223.         if (!IsListEmpty(&myList))
  224.         {
  225.            GT_SetGadgetAttrs(ArchiGadgets[GD_ArchiGadget10 - 9], ArchiWnd, NULL,
  226.               GTLV_Labels, ~0,
  227.               TAG_END);
  228.             
  229.             GT_SetGadgetAttrs(ArchiGadgets[GD_ArchiGadget10 - 9], ArchiWnd, NULL,
  230.               GTLV_Labels, &myList,
  231.               TAG_END);
  232.         }
  233.                
  234.         
  235.     if ( ! ( ArchiWnd = OpenWindowTags( NULL,
  236.                 WA_Left,    ArchiLeft,
  237.                 WA_Top,        ArchiTop,
  238.                 WA_Width,    ArchiWidth,
  239.                 WA_Height,    ArchiHeight + offy,
  240.                 WA_IDCMP,    STRINGIDCMP|LISTVIEWIDCMP|BUTTONIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_VANILLAKEY|IDCMP_RAWKEY,
  241.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  242.                 WA_Gadgets,    ArchiGList,
  243.                 WA_Title,    GetString(&li, MSG_TITLE_ARCHIWINDOW),
  244.                                 WA_CustomScreen, Scr,
  245.                 TAG_DONE )))
  246.     return( FALSE );
  247.        
  248.     GT_RefreshWindow( ArchiWnd, NULL );
  249.  
  250.     return( TRUE );
  251. }
  252.  
  253. BOOL CloseArchiWindow( void )
  254. {
  255.     if ( ArchiWnd ) {
  256.         CloseWindow( ArchiWnd );
  257.         ArchiWnd = NULL;
  258.     }
  259.  
  260.     if ( ArchiGList ) {
  261.         FreeGadgets( ArchiGList );
  262.         ArchiGList = NULL;
  263.     }
  264.         return FALSE;
  265. }
  266.  
  267. BOOL ArchiGadget00Clicked( void )
  268. {
  269.         return TRUE;               
  270. }     
  271.    
  272. BOOL ArchiGadget10Clicked( void )
  273. {
  274.         return TRUE;       
  275. }
  276.  
  277. BOOL ArchiGadget20Clicked( void )
  278. {
  279.         CloseArchiWindow();
  280.         return FALSE;  
  281. }
  282.  
  283. BOOL ArchiGadget30Clicked( void )
  284. {
  285.      struct crunch *cmd;
  286.        
  287.      if (cmd = (struct crunch *)FindName(&myList, (STRPTR)GetGadString(ArchiGadgets[GD_ArchiGadget00 - 9])))
  288.      {
  289.             Remove((struct Node *)cmd);
  290.             FreeVec(cmd);
  291.             
  292.             GT_SetGadgetAttrs(ArchiGadgets[GD_ArchiGadget10 - 9], ArchiWnd, NULL,
  293.               GTLV_Labels, ~0,
  294.               TAG_END);
  295.             
  296.             GT_SetGadgetAttrs(ArchiGadgets[GD_ArchiGadget10 - 9], ArchiWnd, NULL,
  297.               GTLV_Labels, &myList,
  298.               TAG_END);
  299.      } 
  300.      
  301.      return TRUE;                         
  302. }        
  303.  
  304. BOOL ArchiGadget40Clicked( void )
  305. {
  306.         SavePrefs(UseFile);
  307.         CloseArchiWindow();
  308.         return FALSE;       
  309. }  
  310.  
  311. BOOL ArchiGadget50Clicked( void )
  312. {          
  313.         if (nodecmd = AllocVec(sizeof(struct crunch), MEMF_CLEAR))
  314.         {
  315.                  nodecmd->cr_Node.ln_Name = strdup(GetGadString(ArchiGadgets[GD_ArchiGadget00 - 9]));
  316.                  if ( (!FindName(&myList,GetGadString(ArchiGadgets[GD_ArchiGadget00 - 9]))) && (strlen(nodecmd->cr_Node.ln_Name) > 0))
  317.                  {
  318.                         if (PrefsWnd == NULL)
  319.                         { 
  320.                              addflag = OpenPrefsWindow();
  321.                         }       
  322.                  }
  323.                  else
  324.                    FreeVec(nodecmd);
  325.        }
  326.        return TRUE;
  327. }
  328.         
  329. BOOL ArchiGadget60Clicked( void )
  330. {
  331.          SavePrefs(SaveFile);
  332.          SavePrefs(UseFile);
  333.          CloseArchiWindow();
  334.          return FALSE;
  335. }
  336.  
  337. BOOL ArchiGadget70Clicked( void )
  338. {       
  339.        addflag = FALSE;
  340.        if (nodecmd = (struct crunch *)FindName(&myList, GetGadString(ArchiGadgets[GD_ArchiGadget00 - 9])))
  341.        {
  342.         if (PrefsWnd == NULL)
  343.         {
  344.             if (OpenPrefsWindow())
  345.             {
  346.               GT_SetGadgetAttrs(PrefsGadgets[GD_PrefsGadget20 - 17], PrefsWnd, NULL,
  347.                 GTST_String, nodecmd->cr_ext);
  348.               GT_SetGadgetAttrs(PrefsGadgets[GD_PrefsGadget30 - 17], PrefsWnd, NULL,
  349.                 GTST_String, nodecmd->cr_option);
  350.               GT_SetGadgetAttrs(PrefsGadgets[GD_PrefsGadget40 - 17], PrefsWnd, NULL,
  351.                 GTCB_Checked, nodecmd->cr_rep);
  352.                 
  353.               oldoption = strdup(nodecmd->cr_option);
  354.               oldext = strdup(nodecmd->cr_ext);
  355.               oldrep = nodecmd->cr_rep;
  356.             }  
  357.        }
  358.       }     
  359.       return TRUE;                      
  360. }
  361.         
  362.  
  363.